﻿package com.meganracing.video{
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.display.Sprite;
	import flash.events.Event;

	public class MVideoPlayer extends Sprite {
		private var _xml:XML=new XML  ;
		private var _urq:URLRequest=null;
		private var _uld:URLLoader=null;
		
		private var _loaded:Boolean = false;

		private var MV_VID:int=0;
		private var MV_XML_URL="http://www.meganracing.com/video/dataxml.asp";
		private var MV_XML_PATH:String="";
		private var MV_XML_PS:String="?vid=";

		//
		public function MVideoPlayer(vid:int=0,xmlurl:String="",xmlload:Boolean=false) {
			if (vid>0) {
				this.MV_VID=vid;
				xmlload=true;
			}
			if (xmlurl!="") {
				XML_URL=xmlurl;
			}

			if (xmlload==true) {
				this._xml_load();
			}
		}

		//
		public function set VID(vid:int):void {
			this.MV_VID=vid;
		}

		public function set XML_URL(xmlurl:String):void {
			this.MV_XML_URL=xmlurl;
		}

		public function set XML_PATH(xmlpath:String):void {
			this.MV_XML_PATH=xmlpath;
		}

		public function set XML_PS(xmlps:String):void {
			this.MV_XML_PS=xmlps;
		}

		public function mtrigger():void {
			this._xml_load();
		}

		//
		private function _video_url():String {
			return this.MV_XML_URL+""+MV_XML_PATH+""+MV_XML_PS+""+MV_VID;
		}

		private function _xml_load() {
			var _vurl:String=this._video_url();
			_urq=new URLRequest(_vurl);
			_uld=new URLLoader(_urq);
			_uld.addEventListener(Event.COMPLETE,_xml_loaded);
		}

		private function _xml_loaded(ev:Event):void {
			_xml=XML(_uld.data);
			_loaded = true;
			
			this.dispatchEvent(new Event("MVP_LOADED"));
		}
		
		public function getXML():XML {
			return this._xml;
		}

		public function getData() {

		}
	}
}